package com.bfly.mall.order.service.impl;

import com.bfly.core.base.service.BaseServiceImpl;
import com.bfly.mall.order.dao.OrderLogsMapper;
import com.bfly.mall.order.entity.Order;
import com.bfly.mall.order.entity.OrderLogs;
import com.bfly.mall.order.enums.OrderOpTypeEnum;
import com.bfly.mall.order.service.IOrderLogsService;
import com.bfly.mall.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 长沙商脉科技有限公司
 * @date 2020/4/19 19:05
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class OrderLogsServiceImpl extends BaseServiceImpl<OrderLogs, Integer> implements IOrderLogsService {

    @Autowired
    private IOrderService orderService;
    @Autowired
    private OrderLogsMapper logsMapper;

    @Override
    public List<OrderLogs> getLogs(String orderNo) {
        return logsMapper.getOrderLogs(orderNo);
    }

    @Override
    public List<OrderLogs> getLogs(String orderNo, OrderOpTypeEnum type) {
        if (type == null) {
            return getLogs(orderNo);
        }
        return logsMapper.getOrderLogsByType(orderNo, type.getId());
    }

    @Override
    public OrderLogs getLatestApplyRefundLogs(String orderNo) {
        Order order = orderService.getOrder(orderNo);
        return logsMapper.getLatestApplyRefundLogs(order.getOrderNo(),
                OrderOpTypeEnum.REQUEST_REFUND_MEMBER.getId(),
                OrderOpTypeEnum.REQUEST_REFUND_PRODUCT_MEMBER.getId());
    }
}
